package com.cmcc.driver.ui.main.viewmodel

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.cmcc.driver.data.DriverRequest
import com.cmcc.driver.data.entity.response.OrderRecord
import com.cmcc.shared.utils.L
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

/**
 * Author: jiangxin
 * Date: 2019/11/15
 * Description:
 */
class OrderRecordViewModel : ViewModel() {
    val records = MutableLiveData<OrderRecord>()

    fun getRecords(page: Int, pageSize: Int) {

        viewModelScope.launch(Dispatchers.Main) {
            try {
                val response = DriverRequest.getInstance().getOrderRecords(page, pageSize)
                if(response.isSuccessful) {
                    val data = response.body()
                    records.value = data?.data
                }else {

                }
            } catch (e: Exception) {
                L.d("e :" + e.message + "," + e.cause)
            }
        }
    }

}